if ($this.flowData.approvalType === "yes") {
    $this.$http.post("vetechPush/projectFilePush?billId=" + $this.billId)
        .then((res) => {
            if (res.data.code === 280) {
                $this.$message.success("项目立项同步完成")
                $this.spinning = false
            } else {
                $this.$message.error("胜意费控数据推送失败，请联系管理员")
                $this.approvalFlag = true;
                $this.spinning = false
            }
        })

    // 创建子项目
    const model = $this.model;
    let whId = '7857ca223bedbfc31a0bd737f9a38b57';
    const table_1757916909756_QPOEx = model.table_1757916909756_QPOEx;
    if (Array.isArray(table_1757916909756_QPOEx) && table_1757916909756_QPOEx.length > 0) {
        table_1757916909756_QPOEx.forEach(async e => {
            let id = $this.$util.uuid(); // 表单id
            let no = $this.$util.uuid(); // 表单no
            const saveObj = {
                bill_id: e.table_body_id ? e.table_body_id : id,
                bill_no: no,
                bill_type: whId,
                create_company_id: model["create_company_id"],
                create_company_name: model["create_company_name"],
                create_date: model["create_date"],
                create_dept_id: model["create_dept_id"],
                create_dept_name: model["create_dept_name"],
                create_user_id: model["create_user_id"],
                create_user_name: model["create_user_name"],
                select_1742617283496_E0wUw: model.select_1742205505738_nar4L, // 功能分类
                input_1753877062485_VEaHJ: model.number_1747460794402_TzvGd, // 兼容范围高/mm
                systemSelect_1742617283496_C2PmD: model.systemSelect_1742615105116_2TqK4, // 电控负责人
                systemSelect_1742617283496_C2PmD_ID: model.systemSelect_1742615105116_2TqK4_ID, // 电控负责人_ID
                rangePicker_1742617283496_aZnTJ: model.rangePicker_1742205576986_7Iknp, // 计划时间
                number_1747461485363_4Xvz4: model.number_1747460796942_bQp6H, // 外形尺寸高/mm
                select_1742616727274_HEQRx: model.select_1742614810379_ZxrhS, // 承接事业部
                number_1742617283496_bBoHU: e.body_1757916985464_c2rbS, // 设备数量
                number_1747461485363_KKTvq: model.number_1747460797730_2wttX, // 外形尺寸长/mm
                selectStr_1747449931698_EKb0u: model.selectStr_1747016399106_NRRye, // 选择客户档案
                selectStr_1747449931698_EKb0u_ID: model.selectStr_1747016399106_NRRye_ID, // 选择客户档案_ID
                input_1753877061942_mopfS: model.number_1747460792169_tm9Ir, // 兼容范围长/mm
                select_1742617283496_5fYa3: e.body_1757917241695_54u6L, // 项目是否外包
                input_1747450011927_fgbHe: model.input_1747016454595_gitbY, // 终端客户
                systemSelect_1742617283496_MvtJ2: model.systemSelect_1742616582958_0ZShb, // 电工组长
                systemSelect_1742617283496_MvtJ2_ID: model.systemSelect_1742616582958_0ZShb_ID, // 电工组长_ID
                input_1742617283496_Fd67L: model.input_1742205241184_M3UgM, // 设备名称
                select_1742617283496_CzAdO: model.select_1742615323571_A8CqU, // 结算币别
                input_1747449964633_Ublir: model.input_1688608906477_jFYCL, // 签约客户
                systemSelect_1742617283496_KdO3g: model.systemSelect_1688608855355_l9XZc, // 研发负责人
                systemSelect_1742617283496_KdO3g_ID: model.systemSelect_1688608855355_l9XZc_ID, // 研发负责人_ID
                input_1742617283496_DwCls: model.input_1742205431937_eXyZQ, // 产能
                systemSelect_1742617283496_etrPh: model.systemSelect_1742616582078_YGvIM, // 软件负责人
                systemSelect_1742617283496_etrPh_ID: model.systemSelect_1742616582078_YGvIM_ID, // 软件负责人_ID
                input_1742192459958_CyvZA: e.body_1757916960887_lWH4a, // 子项目名称
                cascader_1742617283496_sGyVr: model.cascader_1742615105116_lr9bm, // 国家
                systemSelect_1742617283496_FpwPZ: model.systemSelect_1730808240814_s7hZA, // 市场负责人
                systemSelect_1742617283496_FpwPZ_ID: model.systemSelect_1730808240814_s7hZA_ID, // 市场负责人_ID
                selectStr_1742192391102_1HPJ5: model.bill_no, // 选择项目立项
                selectStr_1742192391102_1HPJ5_ID: model.bill_id, // 选择项目立项_ID
                input_1742192419073_WvMR0: model.input_1688608734780_FzYra, // 项目名称
                input_1742194398803_srflJ: model.input_1730259930643_UvVxt, // 商机编号
                input_1742617697770_XAsv5: e.body_1757917087726_IHcp1, // 客户技术对接人
                input_1742617411554_ct1cI: e.body_1757917099294_HJcC1, // 联系方式
                textarea_1742617283496_Rjsgc: e.body_1757917108727_v9cXD, // 要求
                select_1753857064484_uDSAd: e.body_1757917220106_Y4kv0, // 是否为研发项目
                textarea_1756644940462_E1DUX: e.body_1757917115304_e7EuR, // 工程备注
                textarea_1756644986781_YdJ0O: e.body_1757917131106_8vjw9, // 市场备注
                input_1756645043739_PRahI: e.body_1757917162815_EBJM1, // 标识码
                input_1744877994223_rn5Gp: e.body_1757917213229_ZBcze, // 基地名称
                selectStr_1744877901073_tq4po: e.body_1757917194600_G6TR0, // 基地
                selectStr_1744877901073_tq4po_ID: e.body_1757917194600_G6TR0_ID, // 基地_ID
                systemSelect_1744877994223_mrJdk: e.body_1757993851221_0EA7F, // 基地负责人
                systemSelect_1744877994223_mrJdk_ID: e.body_1757993851221_0EA7F_ID, // 基地负责人_ID
                datepicker_1753863236694_tfmeF: e.body_1757917026391_AA7r9, // 接单日期
                datepicker_1753863231445_6BHI1: e.body_1757917036463_WfRRB, // 合同交期
                cascader_1744877994223_oQWdV: e.body_1757993851221_4sS30, // 出货目的地
                select_1758072974534_8ugz4: e.body_1757917005881_NTtWc, // 单位
                select_1742617283496_X15Xm: '05f7b578b6ac289f875615270a607f26', // 子项目阶段
                systemSelect_1760152672212_kGvzj: e.body_1760168564003_jz1Wm, // 抄送人
                systemSelect_1760152672212_kGvzj_ID: e.body_1760168564003_jz1Wm_ID, // 抄送人_ID
                select_1760680533246_zM7zV: model.select_1760680424648_gi2nr, // 行业大类
                input_1761114456317_5C7HT: e.body_1757916962042_FbZLr, // 客户下单名称
                select_1756645348747_sEtDb: model.select_1756645303493_rPhTw, // 下单组织
                select_1753863137389_GPp6U: model.select_1762831961596_8V8OI, // 设备类别
                input_1762248119073_RmXqY: model.input_1762245347478_klQS3, // 终端客户简称
                input_1762248081964_SJ2e0: model.input_1757917596882_jxnZP, // 终端客户简称
                systemSelect_1742617283496_nCnoD: e.body_1757917050862_GuXXH, // 机构负责人
                systemSelect_1742617283496_nCnoD_ID: e.body_1757917050862_GuXXH_ID, // 机构负责人_ID
            }
            if (!saveObj.input_1742192419073_yXVRy) {
                const addAfterObj = await getDataById('bill_id', model.bill_id, 'df3e3289f0ad82cf6bfaedaad46201c3');
                console.log(`output->addAfterObj`, addAfterObj)
                // 项目编号
                saveObj.input_1742192419073_yXVRy = addAfterObj.commonNumber_1690186634801_aSfOG
            }
            console.log(`output->saveObj`, saveObj)
            for (let k in saveObj) {
                if (!saveObj[k]) {
                    delete saveObj[k];
                }
            }
            console.log(`output->deleted after saveObj`, saveObj)
            const files = Array.isArray($this.files) ? $this.files : [];
            $this.spinning = true
            $this.$http.post(`/wind/form/save/zxm/add`,
                getFormData({
                    obj: saveObj,
                    files: files,
                })
            )
                .then(res => res.data.code)
                .then(code => {
                    if (code === 280) {
                        $this.$http.post('formsBusiness/copyTheAttachment',
                            getFormData({
                                parentId: model.bill_id,
                                whId: whId,
                                billId: id,
                                parentFileStrName: 'uploadFile_1688609943921_2JWsA',
                                fileStrName: 'uploadFile_1744612023217_HzMai'
                            })
                        )
                            .then(res => {
                                if (res.data.code === 280) {
                                    $this.$http.post(`/activiti/createFlow/${whId}/${saveObj.bill_id}`)
                                        .then(response => {
                                            if (response.data.code !== 280) {
                                                let errMsg = response.data.msg ? $this.$t(response.data.msg) : '发起【子项目】流程失败';
                                                $this.$message.error(errMsg)
                                            }
                                        }).catch(e => {
                                        $this.$message.error(e.message)
                                    });
                                }
                            })
                    } else {
                        $this.$message.error("系统错误，请联系管理员！！！");
                    }
                })
                .catch(err => {
                    $this.$message.error(err.message);
                })
                .finally(() => $this.spinning = false)
        })
    }
}

async function getDataById(strName, id, whId) {
    const whereList = [
        {
            key: $this.$util.uuid(),
            str: strName,
            condition: 'eq',
            't_value': id,
            whId: whId,
            type: 'head',
        },
    ]
    let formData = new FormData();
    formData.append('where', JSON.stringify(whereList));
    formData.append('authority', 'false')
    const res = await $this.$http.post(`/wind/tableByWhId/${whId}`, formData)
    const list = res.data.list;
    return (Array.isArray(list) && list.length > 0) ? list[0] : {}
}

function getFormData(param) {
    const formData = new FormData();
    if (!param || Object.values(param).length <= 0) return formData;
    for (let k in param) {
        if (Object.prototype.toString.call(param[k]) === '[object String]') {
            formData.append(k, param[k])
        } else {
            formData.append(k, JSON.stringify(param[k]))
        }
    }
    return formData;
}